package dtaskboard.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.VerticalPanel;

public class DialogUtil {

  public static void closableDialog(String header, String contents) {
    // Create a dialog box and set the caption text
    final DialogBox dialogBox = new DialogBox();
    dialogBox.setGlassEnabled(true);
    dialogBox.setAutoHideEnabled(true);
    dialogBox.setHTML(header);

    // Create a table to layout the content
    VerticalPanel dialogContents = new VerticalPanel();
    dialogContents.setSpacing(4);
    dialogBox.setWidget(dialogContents);

    // Add some text to the top of the dialog
    HTML details = new HTML(contents);
    dialogContents.add(details);
    dialogContents.setCellHorizontalAlignment(details,
        HasHorizontalAlignment.ALIGN_CENTER);

    // Add a close button at the bottom of the dialog
    Button closeButton = new Button("Fechar", new ClickHandler() {
      @Override
      public void onClick(ClickEvent event) {
        dialogBox.hide();
      }
    });
    dialogContents.add(closeButton);
    dialogContents.setCellHorizontalAlignment(closeButton,
        HasHorizontalAlignment.ALIGN_RIGHT);

    dialogBox.center();
    dialogBox.show();

  }

}
